<?php
namespace app\admin\controller;

use app\common\controller\Back;

class Site extends Back
{
    protected function initialize()
    {
        parent::initialize();
    }
    
    public function index()
    {
        $form = dcFormCreate([
            'name'         => 'adminSiteIndex',
            'action'       => dcUrl('admin/site/update'),
            'items'        => $this->formItems(config('site.')),
            'reset'        => '重置',
            'class_button' => 'text-left',
        ]);

        $this->assign('form',$form);

        $this->assign($this->site);

        return $this->fetch();
    }

    public function update()
    {
        $post = dcArrayFilter(input('post.'), array_keys($this->formItems()));

        $this->configSave('./config/site.php', $post, 'admin/site/index');
    }
    
    private function formItems($data=[])
    {
        return [
            'name' => [
                'type'        => 'text',
                'value'       => $data['name'],
                'required'    => true,
                'title'       => '网站名称',
                'class_row'   => 'mb-3',
                'class_label' => 'form-label',
            ],
            'host' => [
                'type'        => 'text',
                'value'       => $data['host'],
                'required'    => true,
                'title'       => '网站域名',
                'class_row'   => 'mb-3',
                'class_label' => 'form-label',
            ],
            'title' => [
                'type'        => 'text',
                'value'       => $data['title'],
                'required'    => true,
                'title'       => '网站标题',
                'class_row'   => 'mb-3',
                'class_label' => 'form-label',
            ],
            'keywords' => [
                'type'        => 'text',
                'value'       => $data['keywords'],
                'required'    => true,
                'title'       => '网站关键字',
                'class_row'   => 'mb-3',
                'class_label' => 'form-label',
            ],
            'description' => [
                'type'        => 'text',
                'value'       => $data['description'],
                'required'    => true,
                'title'       => '网站描述',
                'class_row'   => 'mb-3',
                'class_label' => 'form-label',
            ],
            'phone' => [
                'type'        => 'text',
                'value'       => $data['phone'],
                'required'    => false,
                'title'       => '联系电话',
                'class_row'   => 'mb-3',
                'class_label' => 'form-label',
            ],
            'email' => [
                'type'        => 'text',
                'value'       => $data['email'],
                'required'    => false,
                'title'       => '站长邮箱',
                'class_row'   => 'mb-3',
                'class_label' => 'form-label',
            ],
            'icp' => [
                'type'        => 'text',
                'value'       => $data['icp'],
                'required'    => false,
                'title'       => 'ICP备案号',
                'class_row'   => 'mb-3',
                'class_label' => 'form-label',
            ],
            'icp_permit' => [
                'type'        => 'text',
                'value'       => $data['icp_permit'],
                'required'    => false,
                'title'       => 'ICP经营许可证',
                'class_row'   => 'mb-3',
                'class_label' => 'form-label',
            ],
            'icp_police' => [
                'type'        => 'text',
                'value'       => $data['icp_police'],
                'required'    => false,
                'title'       => '公安网备案号',
                'class_row'   => 'mb-3',
                'class_label' => 'form-label',
            ],
            'tongji_header' => [
                'type'        => 'textarea',
                'value'       => $data['tongji_header'],
                'required'    => false,
                'title'       => '顶部统计代码',
                'rows'        => 3,
                'class_row'   => 'mb-3',
                'class_label' => 'form-label',
            ],
            'tongji_footer' => [
                'type'        => 'textarea',
                'value'       => $data['tongji_footer'],
                'required'    => false,
                'title'       => '底部统计代码',
                'rows'        => 3,
                'class_row'   => 'mb-3',
                'class_label' => 'form-label',
            ],
        ];
    }
}